package leetcode3;

import java.util.*;

public class Day1 {



    List<String> ret = new ArrayList<>();//记录总结果
    StringBuilder path = new StringBuilder();//记录一次的结果
    Map<Character,String> map = new HashMap<>();//存放数字对应的字符串
    public List<String> letterCombinations(String digits) {
        if(digits.equals("")) return ret;
        map.put('2',"abc");
        map.put('3',"def");
        map.put('4',"ghi");
        map.put('5',"jkl");
        map.put('6',"mno");
        map.put('7',"pqrs");
        map.put('8',"tuv");
        map.put('9',"wxyz");
        dfs(digits,0);
        return ret;
    }
    private void dfs(String s,int pos) {
        if(path.length() == s.length()) {
            ret.add(path.toString());
            return;
        }
        String strT = map.get(s.charAt(pos)); //拿到数字对应的字符串
        for(int i=0;i<strT.length();i++) { //遍历该字符串
            path.append(strT.charAt(i));
            dfs(s,pos+1);
            //回溯,拼接下一个字符
            path.deleteCharAt(path.length()-1);
        }
    }


}
